import 'dart:async';

import 'package:qgchat/bloc/blocProvider.dart';
import 'package:qgchat/common/global/global.dart';

import 'package:qgchat/http/apis/user.dart';
import 'package:qgchat/http/models/releaseVideoModel.dart';

class ReleaseVideoBloc implements BlocBase {
  List<ReleaseVideoModel> list = [];

    bool isFirstLoading = true; // 是否第一次加载

  ReleaseVideoBloc() {
    getMake();
  }

  // ##########  DEFAULT  ##############

  final List<ReleaseVideoModel> callDefault = [];

  // ##########  STREAMS  ##############
  /// 预约stream
  StreamController<List<ReleaseVideoModel>> _call =
      StreamController.broadcast();
  Sink<List<ReleaseVideoModel>> get _callSink => _call.sink;
  Stream<List<ReleaseVideoModel>> get callStream => _call.stream;

  void dispose() {
    _call.close();
  }

  // ##########  HANDLING  ##############

  /// 获取发布的视频列表
  void getMake() async {
    List<ReleaseVideoModel> result = await UserApis.releaselist();
    if (result.isNotEmpty) {
      isFirstLoading = false;
      list.addAll(result);
      _callSink.add(list);
    } else {
      isFirstLoading = false;
      showToast("已经到底拉~");
    }
  }
}
